<!-- HTML header for doxygen 1.8.4-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
		<meta http-equiv="X-UA-Compatible" content="IE=9"/>
		<meta name="generator" content="Doxygen 1.8.4"/>
		<title>exceptions4c: e4c_signal_mapping Struct Reference</title>
		<link href="tabs.css" rel="stylesheet" type="text/css"/>
		<link href="exceptions4c.css" rel="stylesheet" type="text/css" />
		<!-- <link href="sheep_016.png" rel="shortcut icon" /> -->
		<link href="" rel="shortcut icon">
		<script type="text/javascript" src="jquery.js"></script>
		<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
		<link href="exceptions4c.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
				<div id="titlearea">
					<table cellspacing="0" cellpadding="0">
						<tbody>
							<tr style="height: 56px;">
									<td id="projectlogo"><img alt="Logo" src="sheep_064.png"/></td>
									<td style="padding-left: 0.5em;">
										<div id="projectname">
											exceptions4c
											&nbsp;
											<span id="projectnumber">version 3.0</span>
										</div>
											<div id="projectbrief">An exception handling framework for C</div>
									</td>
							</tr>
						</tbody>
				</table>
			</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.4 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="functions.html"><span>Data&#160;Fields</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('structe4c__signal__mapping.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#pub-attribs">Data Fields</a>  </div>
  <div class="headertitle">
<div class="title">e4c_signal_mapping Struct Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Represents a map between a signal and an exception.  
 <a href="structe4c__signal__mapping.html#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-attribs"></a>
Data Fields</h2></td></tr>
<tr class="memitem:a0c9e08ebdad375650d1946b0e8d58d19"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structe4c__signal__mapping.html#a0c9e08ebdad375650d1946b0e8d58d19">signal_number</a></td></tr>
<tr class="memdesc:a0c9e08ebdad375650d1946b0e8d58d19"><td class="mdescLeft">&#160;</td><td class="mdescRight">The signal to be converted.  <a href="#a0c9e08ebdad375650d1946b0e8d58d19">More...</a><br/></td></tr>
<tr class="separator:a0c9e08ebdad375650d1946b0e8d58d19"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a05922dc349043f7de90335829432f062"><td class="memItemLeft" align="right" valign="top">const <a class="el" href="structe4c__exception__type.html">e4c_exception_type</a> *const&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structe4c__signal__mapping.html#a05922dc349043f7de90335829432f062">exception_type</a></td></tr>
<tr class="memdesc:a05922dc349043f7de90335829432f062"><td class="mdescLeft">&#160;</td><td class="mdescRight">The exception representing the signal.  <a href="#a05922dc349043f7de90335829432f062">More...</a><br/></td></tr>
<tr class="separator:a05922dc349043f7de90335829432f062"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Represents a map between a signal and an exception. </p>
<p>A signal is an asynchronous notification sent by the operating system to a process in order to notify it of an event that occurred. Most of the signals will, by default, crash the program as soon as they are raised. <b>exceptions4c</b> can convert signals to exceptions, so they can be easily handled.</p>
<p>For example, a <em>suspicious</em> or <em>dangerous</em> part of the program could be wrapped up with <code><a class="el" href="e4c_8h.html#a28599e8ac99ea9faff60a2258a914aee" title="Introduces a block of code aware of exceptions. ">try</a></code> blocks and then <code><a class="el" href="e4c_8h.html#a629585c5169ebdb440b9015f8e87b4df" title="Introduces a block of code capable of handling a specific type of exceptions. ">catch</a></code> <em>segmentation faults</em> or <em>divisions by zero</em>. Then the program would clean up and continue normally:</p>
<div class="fragment"><div class="line"><a class="code" href="e4c_8h.html#a27678c11fa7d4e2a9436f527cc194013" title="Introduces a block of code which will use a new exception context. ">e4c_using_context</a>(E4C_TRUE){</div>
<div class="line">    <span class="keywordtype">int</span> * pointer = NULL;</div>
<div class="line">    <span class="keywordflow">try</span>{</div>
<div class="line">        <span class="keywordtype">int</span> oops = *pointer;</div>
<div class="line">    }<span class="keywordflow">catch</span>(BadPointerException){</div>
<div class="line">        printf(<span class="stringliteral">&quot;No problem ;-)&quot;</span>);</div>
<div class="line">    }<span class="keywordflow">finally</span>{</div>
<div class="line">        <span class="comment">// clean up...</span></div>
<div class="line">    }</div>
<div class="line">}</div>
</div><!-- fragment --><p>In order to perform the conversion, <b>exceptions4c</b> <em>maps</em> signals to exceptions.</p>
<p>The simplest way to get this working is by calling the function <code><a class="el" href="e4c_8h.html#a1e27be2186952ed77b4591f48c5d11cd" title="Begins an exception context. ">e4c_context_begin</a></code>. This function will set up the <a class="el" href="e4c_8h.html#ac4a53949d14a14386d0fd351e2d035eb">default mappings</a> for the available signals in the platform, when passed <code>handle_signals=true</code>.</p>
<p>If you need to be more specific about which signals get converted to exceptions, you can define an array of <a class="el" href="structe4c__signal__mapping.html">signal mappings</a> and then pass it to the function <code><a class="el" href="e4c_8h.html#a8a4c54a4d7cd10568b639749e8ec0e1f" title="Assigns the specified signal mappings to the exception context. ">e4c_context_set_signal_mappings</a></code>.</p>
<p>An array of signal mappings is defined through three macros:</p>
<ul>
<li><code><a class="el" href="e4c_8h.html#a598e01198e8ce022fdb32ae7145803f6" title="Maps a specific signal number to a given exception type. ">E4C_SIGNAL_MAPPING</a></code></li>
<li><code><a class="el" href="e4c_8h.html#acce379ab06acbdb14eb15e55cdba4631" title="Ignores a specific signal number. ">E4C_IGNORE_SIGNAL</a></code></li>
<li><code><a class="el" href="e4c_8h.html#ad9a799b298c1f39c427364bfc7bfb230" title="Represents a null signal mapping literal. ">E4C_NULL_SIGNAL_MAPPING</a></code></li>
</ul>
<p>While <code>E4C_SIGNAL_MAPPING</code> tells the system to convert a specific signal to a given exception, <code>E4C_IGNORE_SIGNAL</code> allows you to disregard the signal and continue (even if unmeaningful).</p>
<p>Every array of signal mappings <b>needs</b> to be terminated with the <code>E4C_NULL_SIGNAL_MAPPING</code> element, so the system finds out how many mappings are there in a given array.</p>
<div class="fragment"><div class="line"><span class="keyword">const</span> <a class="code" href="structe4c__signal__mapping.html" title="Represents a map between a signal and an exception. ">e4c_signal_mapping</a> my_signal_mappings[] = {</div>
<div class="line">    <a class="code" href="e4c_8h.html#a598e01198e8ce022fdb32ae7145803f6" title="Maps a specific signal number to a given exception type. ">E4C_SIGNAL_MAPPING</a>(SIGABRT, Exception1),</div>
<div class="line">    <a class="code" href="e4c_8h.html#a598e01198e8ce022fdb32ae7145803f6" title="Maps a specific signal number to a given exception type. ">E4C_SIGNAL_MAPPING</a>(SIGINT, Exception2),</div>
<div class="line">    <a class="code" href="e4c_8h.html#acce379ab06acbdb14eb15e55cdba4631" title="Ignores a specific signal number. ">E4C_IGNORE_SIGNAL</a>(SIGTERM),</div>
<div class="line">    ...</div>
<div class="line">    <a class="code" href="e4c_8h.html#ad9a799b298c1f39c427364bfc7bfb230" title="Represents a null signal mapping literal. ">E4C_NULL_SIGNAL_MAPPING</a></div>
<div class="line">}</div>
</div><!-- fragment --><p>Once the array is properly defined, it can be passed to the function <code>e4c_context_set_signal_mappings</code>. This way, only the specified signals will be handled as exceptions, and they will be converted to the specified exceptions.</p>
<div class="fragment"><div class="line"><a class="code" href="e4c_8h.html#a27678c11fa7d4e2a9436f527cc194013" title="Introduces a block of code which will use a new exception context. ">e4c_using_context</a>(E4C_FALSE){</div>
<div class="line"></div>
<div class="line">    e4c_context_set_signal_mappings(my_signal_mappings);</div>
<div class="line">    ...</div>
<div class="line">}</div>
</div><!-- fragment --><p>These are some of the signals you can handle:</p>
<ul>
<li><code>SIGFPE</code> when dividing by <em>zero</em>.</li>
<li><code>SIGSEGV</code> when dereferencing an invalid pointer.</li>
<li><code>SIGINT</code> when a user interrupts the process.</li>
<li><code>SIGTERM</code> when a process is requested to be terminated.</li>
</ul>
<dl class="section see"><dt>See Also</dt><dd><a class="el" href="e4c_8h.html#a1e27be2186952ed77b4591f48c5d11cd" title="Begins an exception context. ">e4c_context_begin</a> </dd>
<dd>
<a class="el" href="e4c_8h.html#a8a4c54a4d7cd10568b639749e8ec0e1f" title="Assigns the specified signal mappings to the exception context. ">e4c_context_set_signal_mappings</a> </dd>
<dd>
<a class="el" href="e4c_8h.html#a7290cbfb8abb0b2ecf338cdb4de5d6df" title="Retrieves the signal mappings for the current exception context. ">e4c_context_get_signal_mappings</a> </dd>
<dd>
<a class="el" href="e4c_8h.html#a598e01198e8ce022fdb32ae7145803f6" title="Maps a specific signal number to a given exception type. ">E4C_SIGNAL_MAPPING</a> </dd>
<dd>
<a class="el" href="e4c_8h.html#acce379ab06acbdb14eb15e55cdba4631" title="Ignores a specific signal number. ">E4C_IGNORE_SIGNAL</a> </dd>
<dd>
<a class="el" href="e4c_8h.html#ac4a53949d14a14386d0fd351e2d035eb" title="The array of predefined signal mappings. ">e4c_default_signal_mappings</a> </dd></dl>
</div><h2 class="groupheader">Field Documentation</h2>
<a class="anchor" id="a05922dc349043f7de90335829432f062"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">const <a class="el" href="structe4c__exception__type.html">e4c_exception_type</a>* const e4c_signal_mapping::exception_type</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>The exception representing the signal. </p>

</div>
</div>
<a class="anchor" id="a0c9e08ebdad375650d1946b0e8d58d19"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int e4c_signal_mapping::signal_number</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>The signal to be converted. </p>

</div>
</div>
<hr/>The documentation for this struct was generated from the following file:<ul>
<li><a class="el" href="e4c_8h.html">e4c.h</a></li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.4-->
<!-- start footer part -->
			<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
			  <ul>
				<li class="navelem"><a class="el" href="structe4c__signal__mapping.html">e4c_signal_mapping</a></li>
				<li class="footer">
					<a href="https://code.google.com/p/exceptions4c/" title="exceptions4c version 3.0">
						<img src="sheep_016.png" width="16" height="16" alt="" style="vertical-align: text-bottom;" />
						<strong>exceptions4c</strong>
					</a>
					Reference Documentation
					Generated by
					<a href="http://www.doxygen.org/index.html" title="doxygen 1.8.4">
						<strong>doxygen</strong>
					</a>
				</li>
			  </ul>
			</div>
	</body>
</html>
